<?php
namespace Operation\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\EventManager\EventManagerInterface;
use Zend\View\Model\ViewModel;
use Zend\Session\Container;

class IndexController extends AbstractActionController
{    
    protected $storeTable;
    
    public function setEventManager(EventManagerInterface $events)
    {
        parent::setEventManager($events);
 
        $controller = $this;
        $events->attach('dispatch', function ($e) use ($controller) {
            $controller->layout()->setTemplate('layout/operation');
        }, 100);
 
        return $this;
    }
    
    public function getStoreTable()
    {
        if (!$this->storeTable) {
            $sm = $this->getServiceLocator();
            $this->storeTable = $sm->get('Operation\Model\StoreTable');
        }
        return $this->storeTable;
    }
    
    public function indexAction()
    {        
        $dataCritere = new Container('dataCritere');
        
        return new ViewModel(array(
            'stores' => $this->getStoreTable()->fetchAll(),
            'periodY' => $dataCritere->offsetGet('periodY'),
            'periodM' => $dataCritere->offsetGet('periodM'),
            'semaine' =>$dataCritere->offsetGet('semaine'),
            'specific_date' => $dataCritere->offsetGet('specific_date'),
        ));        
    }
}